<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>class SyntaxSuggest::CodeFrontier - syntax_suggest: Ruby Standard Library Documentation</title>


<script src="../js/navigation.js" defer></script>
<script src="../js/search.js" defer></script>
<script src="../js/search_index.js" defer></script>
<script src="../js/searcher.js" defer></script>
<script src="../js/darkfish.js" defer></script>

<script src="../js/jquery-3.2.0.min.js"></script>

<script src="../js/vue.min.js"></script>
<script src="../js/js.cookie.min.js"></script>

<link href="../css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="../css/rdoc.css" rel="stylesheet">
<link href="../css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../";
  var index_rel_prefix = "../";
  var darkModeCsseHref = "../css/rdoc-dm.css"
  var defaultModeCssHref = "../css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="class">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0.preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="../index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="../table_of_contents.html#pages">Pages</a>
    <a href="../table_of_contents.html#classes">Classes</a>
    <a href="../table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    

    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link">Object
</div>

        
        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-combination">::combination</a>
    <li ><a href="#method-c-new">::new</a>
    <li ><a href="#method-i-3C-3C">#&lt;&lt;</a>
    <li ><a href="#method-i-can_skip_check-3F">#can_skip_check?</a>
    <li ><a href="#method-i-count">#count</a>
    <li ><a href="#method-i-detect_invalid_blocks">#detect_invalid_blocks</a>
    <li ><a href="#method-i-expand-3F">#expand?</a>
    <li ><a href="#method-i-holds_all_syntax_errors-3F">#holds_all_syntax_errors?</a>
    <li ><a href="#method-i-next_indent_line">#next_indent_line</a>
    <li ><a href="#method-i-pop">#pop</a>
    <li ><a href="#method-i-register_engulf_block">#register_engulf_block</a>
    <li ><a href="#method-i-register_indent_block">#register_indent_block</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="class-SyntaxSuggest::CodeFrontier">
    <h1 id="class-SyntaxSuggest::CodeFrontier" class="class">
      class SyntaxSuggest::CodeFrontier
    </h1>

    <section class="description">
    
<p>There are three main phases in the algorithm:</p>
<ol><li>
<p>Sanitize/format input source</p>
</li><li>
<p>Search for invalid blocks</p>
</li><li>
<p>Format invalid blocks into something meaninful</p>
</li></ol>

<p>The Code frontier is a critical part of the second step</p>

<p>## Knowing where we’ve been</p>

<p>Once a code block is generated it is added onto the frontier. Then it will be sorted by indentation and frontier can be filtered. Large blocks that fully enclose a smaller block will cause the smaller block to be evicted.</p>

<pre class="ruby"><span class="ruby-constant">CodeFrontier</span><span class="ruby-comment">#&lt;&lt;(block) # Adds block to frontier</span>
<span class="ruby-constant">CodeFrontier</span><span class="ruby-comment">#pop # Removes block from frontier</span>
</pre>

<p>## Knowing where we can go</p>

<p>Internally the frontier keeps track of “unvisited” lines which are exposed via ‘next_indent_line` when called, this method returns, a line of code with the highest indentation.</p>

<p>The returned line of code can be used to build a <a href="CodeBlock.html"><code>CodeBlock</code></a> and then that code block is added back to the frontier. Then, the lines are removed from the “unvisited” so we don’t double-create the same block.</p>

<pre class="ruby"><span class="ruby-constant">CodeFrontier</span><span class="ruby-comment">#next_indent_line # Shows next line</span>
<span class="ruby-constant">CodeFrontier</span><span class="ruby-comment">#register_indent_block(block) # Removes lines from unvisited</span>
</pre>

<p>## Knowing when to stop</p>

<p>The frontier knows how to check the entire document for a syntax error. When blocks are added onto the frontier, they’re removed from the document. When all code containing syntax errors has been added to the frontier, the document will be parsable without a syntax error and the search can stop.</p>

<pre class="ruby"><span class="ruby-constant">CodeFrontier</span><span class="ruby-comment">#holds_all_syntax_errors? # Returns true when frontier holds all syntax errors</span>
</pre>

<p>## Filtering false positives</p>

<p>Once the search is completed, the frontier may have multiple blocks that do not contain the syntax error. To limit the result to the smallest subset of “invalid blocks” call:</p>

<pre class="ruby"><span class="ruby-constant">CodeFrontier</span><span class="ruby-comment">#detect_invalid_blocks</span>
</pre>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">





                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-combination" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">combination</span><span
                                class="method-args">(array)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Example:</p>

<pre class="ruby"><span class="ruby-identifier">combination</span>([<span class="ruby-value">:a</span>, <span class="ruby-value">:b</span>, <span class="ruby-value">:c</span>, <span class="ruby-value">:d</span>])
<span class="ruby-comment"># =&gt; [[:a], [:b], [:c], [:d], [:a, :b], [:a, :c], [:a, :d], [:b, :c], [:b, :d], [:c, :d], [:a, :b, :c], [:a, :b, :d], [:a, :c, :d], [:b, :c, :d], [:a, :b, :c, :d]]</span>
</pre>

                              <div class="method-source-code" id="combination-source">
            <pre><span class="ruby-comment"># File syntax_suggest/code_frontier.rb, line 162</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">combination</span>(<span class="ruby-identifier">array</span>)
  <span class="ruby-identifier">guesses</span> = []
  <span class="ruby-value">1</span>.<span class="ruby-identifier">upto</span>(<span class="ruby-identifier">array</span>.<span class="ruby-identifier">length</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">size</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">guesses</span>.<span class="ruby-identifier">concat</span>(<span class="ruby-identifier">array</span>.<span class="ruby-identifier">combination</span>(<span class="ruby-identifier">size</span>).<span class="ruby-identifier">to_a</span>)
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">guesses</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-new" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">new</span><span
                                class="method-args">(code_lines:, unvisited: UnvisitedLines.new(code_lines: code_lines))</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="new-source">
            <pre><span class="ruby-comment"># File syntax_suggest/code_frontier.rb, line 53</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">initialize</span>(<span class="ruby-value">code_lines:</span>, <span class="ruby-value">unvisited:</span> <span class="ruby-constant">UnvisitedLines</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">code_lines:</span> <span class="ruby-identifier">code_lines</span>))
  <span class="ruby-ivar">@code_lines</span> = <span class="ruby-identifier">code_lines</span>
  <span class="ruby-ivar">@unvisited</span> = <span class="ruby-identifier">unvisited</span>
  <span class="ruby-ivar">@queue</span> = <span class="ruby-constant">PriorityEngulfQueue</span>.<span class="ruby-identifier">new</span>

  <span class="ruby-ivar">@check_next</span> = <span class="ruby-keyword">true</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-3C-3C" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">&lt;&lt;</span><span
                                class="method-args">(block)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Add a block to the frontier</p>

<p>This method ensures the frontier always remains sorted (in indentation order) and that each code block’s lines are removed from the indentation hash so we don’t re-evaluate the same line multiple times.</p>

                              <div class="method-source-code" id="3C-3C-source">
            <pre><span class="ruby-comment"># File syntax_suggest/code_frontier.rb, line 148</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">&lt;&lt;</span>(<span class="ruby-identifier">block</span>)
  <span class="ruby-ivar">@unvisited</span>.<span class="ruby-identifier">visit_block</span>(<span class="ruby-identifier">block</span>)

  <span class="ruby-ivar">@queue</span>.<span class="ruby-identifier">push</span>(<span class="ruby-identifier">block</span>)

  <span class="ruby-ivar">@check_next</span> = <span class="ruby-keyword">true</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">block</span>.<span class="ruby-identifier">invalid?</span>

  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-count" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">count</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="count-source">
            <pre><span class="ruby-comment"># File syntax_suggest/code_frontier.rb, line 61</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">count</span>
  <span class="ruby-ivar">@queue</span>.<span class="ruby-identifier">length</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-detect_invalid_blocks" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">detect_invalid_blocks</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Given that we know our syntax error exists somewhere in our frontier, we want to find the smallest possible set of blocks that contain all the syntax errors</p>

                              <div class="method-source-code" id="detect_invalid_blocks-source">
            <pre><span class="ruby-comment"># File syntax_suggest/code_frontier.rb, line 172</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">detect_invalid_blocks</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">combination</span>(<span class="ruby-ivar">@queue</span>.<span class="ruby-identifier">to_a</span>.<span class="ruby-identifier">select</span>(<span class="ruby-operator">&amp;</span><span class="ruby-value">:invalid?</span>)).<span class="ruby-identifier">detect</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">block_array</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">holds_all_syntax_errors?</span>(<span class="ruby-identifier">block_array</span>, <span class="ruby-value">can_cache:</span> <span class="ruby-keyword">false</span>)
  <span class="ruby-keyword">end</span> <span class="ruby-operator">||</span> []
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-expand-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">expand?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="expand-3F-source">
            <pre><span class="ruby-comment"># File syntax_suggest/code_frontier.rb, line 111</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">expand?</span>
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@queue</span>.<span class="ruby-identifier">empty?</span>
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">true</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@unvisited</span>.<span class="ruby-identifier">empty?</span>

  <span class="ruby-identifier">frontier_indent</span> = <span class="ruby-ivar">@queue</span>.<span class="ruby-identifier">peek</span>.<span class="ruby-identifier">current_indent</span>
  <span class="ruby-identifier">unvisited_indent</span> = <span class="ruby-identifier">next_indent_line</span>.<span class="ruby-identifier">indent</span>

  <span class="ruby-keyword">if</span> <span class="ruby-constant">ENV</span>[<span class="ruby-string">&quot;SYNTAX_SUGGEST_DEBUG&quot;</span>]
    <span class="ruby-identifier">puts</span> <span class="ruby-string">&quot;```&quot;</span>
    <span class="ruby-identifier">puts</span> <span class="ruby-ivar">@queue</span>.<span class="ruby-identifier">peek</span>.<span class="ruby-identifier">to_s</span>
    <span class="ruby-identifier">puts</span> <span class="ruby-string">&quot;```&quot;</span>
    <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;  @frontier indent:  #{frontier_indent}&quot;</span>
    <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;  @unvisited indent: #{unvisited_indent}&quot;</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-comment"># Expand all blocks before moving to unvisited lines</span>
  <span class="ruby-identifier">frontier_indent</span> <span class="ruby-operator">&gt;=</span> <span class="ruby-identifier">unvisited_indent</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-holds_all_syntax_errors-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">holds_all_syntax_errors?</span><span
                                class="method-args">(block_array = @queue, can_cache: true)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns true if the document is valid with all lines removed. By default it checks all blocks in present in the frontier array, but can be used for arbitrary arrays of codeblocks as well</p>

                              <div class="method-source-code" id="holds_all_syntax_errors-3F-source">
            <pre><span class="ruby-comment"># File syntax_suggest/code_frontier.rb, line 89</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">holds_all_syntax_errors?</span>(<span class="ruby-identifier">block_array</span> = <span class="ruby-ivar">@queue</span>, <span class="ruby-value">can_cache:</span> <span class="ruby-keyword">true</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">can_cache</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">can_skip_check?</span>

  <span class="ruby-identifier">without_lines</span> = <span class="ruby-identifier">block_array</span>.<span class="ruby-identifier">to_a</span>.<span class="ruby-identifier">flat_map</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">block</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">block</span>.<span class="ruby-identifier">lines</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-constant">SyntaxSuggest</span>.<span class="ruby-identifier">valid_without?</span>(
    <span class="ruby-value">without_lines:</span> <span class="ruby-identifier">without_lines</span>,
    <span class="ruby-value">code_lines:</span> <span class="ruby-ivar">@code_lines</span>
  )
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-next_indent_line" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">next_indent_line</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="next_indent_line-source">
            <pre><span class="ruby-comment"># File syntax_suggest/code_frontier.rb, line 107</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">next_indent_line</span>
  <span class="ruby-ivar">@unvisited</span>.<span class="ruby-identifier">peek</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-pop" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">pop</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a code block with the largest indentation possible</p>

                              <div class="method-source-code" id="pop-source">
            <pre><span class="ruby-comment"># File syntax_suggest/code_frontier.rb, line 103</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">pop</span>
  <span class="ruby-ivar">@queue</span>.<span class="ruby-identifier">pop</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-register_engulf_block" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">register_engulf_block</span><span
                                class="method-args">(block)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>When one element fully encapsulates another we remove the smaller block from the frontier. This prevents double expansions and all-around weird behavior. However this guarantee is quite expensive to maintain</p>

                              <div class="method-source-code" id="register_engulf_block-source">
            <pre><span class="ruby-comment"># File syntax_suggest/code_frontier.rb, line 140</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">register_engulf_block</span>(<span class="ruby-identifier">block</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-register_indent_block" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">register_indent_block</span><span
                                class="method-args">(block)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Keeps track of what lines have been added to blocks and which are not yet visited.</p>

                              <div class="method-source-code" id="register_indent_block-source">
            <pre><span class="ruby-comment"># File syntax_suggest/code_frontier.rb, line 132</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">register_indent_block</span>(<span class="ruby-identifier">block</span>)
  <span class="ruby-ivar">@unvisited</span>.<span class="ruby-identifier">visit_block</span>(<span class="ruby-identifier">block</span>)
  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="private-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Private Instance Methods</h3>
                </header>

                  <div id="method-i-can_skip_check-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">can_skip_check?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Performance optimization</p>

<p>Parsing with ripper is expensive If we know we don’t have any blocks with invalid syntax, then we know we cannot have found the incorrect syntax yet.</p>

<p>When an invalid block is added onto the frontier check document state</p>

                              <div class="method-source-code" id="can_skip_check-3F-source">
            <pre><span class="ruby-comment"># File syntax_suggest/code_frontier.rb, line 74</span>
        <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">can_skip_check?</span>
  <span class="ruby-identifier">check_next</span> = <span class="ruby-ivar">@check_next</span>
  <span class="ruby-ivar">@check_next</span> = <span class="ruby-keyword">false</span>

  <span class="ruby-keyword">if</span> <span class="ruby-identifier">check_next</span>
    <span class="ruby-keyword">false</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-keyword">true</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is a service of <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>, purveyors of fine <a href='https://jamesbritt.bandcamp.com/'>dance noise</a></p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

